package com.example.jussi.myproject;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class AddCard extends AppCompatActivity {
    CardBean cardBean;
    EditText editBusinessName, editName, editJob, editEmail, editPhoneNum, editQQNum, editInfo, editAddr;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_card);
        editBusinessName = (EditText) findViewById(R.id.editBusinessName);
        editName = (EditText) findViewById(R.id.editName);
        editJob = (EditText) findViewById(R.id.editJob);
        editEmail = (EditText) findViewById(R.id.editEmail);
        editPhoneNum = (EditText) findViewById(R.id.editPhoneNum);
        editQQNum = (EditText) findViewById(R.id.EditQQNum);
        editInfo = (EditText) findViewById(R.id.editInfo);
        editAddr = (EditText) findViewById(R.id.editAddress);
    }

    public void commit(View view){
        if(editBusinessName.getText() == null || "".equals(editBusinessName.getText().toString())
                || editName.getText() == null || "".equals(editName.getText().toString())
                || editPhoneNum.getText() == null || "".equals(editPhoneNum.getText().toString())){
            Toast.makeText(this, "公司名称、姓名、电话\n  不能为空！！！", Toast.LENGTH_SHORT).show();
            return;
        }
        cardBean = new CardBean();
        cardBean.setBusinessName(editBusinessName.getText().toString());
        cardBean.setName(editName.getText().toString());
        cardBean.setJob(editJob.getText().toString());
        cardBean.setEmail(editEmail.getText().toString());
        cardBean.setPhoneNum(editPhoneNum.getText().toString());
        cardBean.setQqNum(editQQNum.getText().toString());
        cardBean.setInfo(editInfo.getText().toString());
        cardBean.setAddr(editAddr.getText().toString());
        Intent intent = new Intent();
        intent.putExtra("card", cardBean);
        setResult(RESULT_OK, intent);
        finish();
    }

    public void cancel(View view){
        Intent intent = new Intent();
        setResult(RESULT_CANCELED, intent);
        finish();
    }

}
